package com.itbaima.controller;

import com.itbaima.pojo.entity.User;
import com.itbaima.result.Result;
import com.itbaima.service.UserService;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class CommonController {

    @Autowired
    private UserService userService ;



//    @GetMapping("/index1")
//    public String showLoginPage2() {
//        return "redirect:index1.html"; // 最终解析为 /login.jsp
//    }


    @PostMapping("/login")
    public Result login(@RequestBody User user , HttpSession httpSession){

        log.info("人力资源管理系统登录：{}",user);

        User user2 = userService.login(user);

        httpSession.setAttribute("userId",user2.getUser_id());
        httpSession.setAttribute("name",user2.getName());


        return Result.success(user2);

    }



}
